package com.learn.cloud.validator.annotation;

import com.learn.cloud.validator.constant.ValidatorConstants;
import com.learn.cloud.validator.constraints.IdCardValidator;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.*;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * @description:    身份证校验
 * @author:         cong zhi
 * @createDate:     2022/2/6 16:37
 * @updateUser:     cong zhi
 * @updateDate:     2022/2/6 16:37
 * @updateRemark:   修改内容
 * @version:        v1.0
 */
@Documented
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {IdCardValidator.class})
public @interface IdCard {

    String message() default "身份号码格式有误!";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    /**
     * 是否必填
     * <p>
     * 如果必填，在校验的时候本字段没值就会报错
     */
    boolean required() default true;

    /**
     * @return the regular expression to match
     */
    String regexp() default ValidatorConstants.CARD_REGX;

    @Target({ElementType.FIELD, ElementType.PARAMETER})
    @Retention(RUNTIME)
    @Documented
    @interface List {
        IdCard[] value();
    }
}
